package net.zjitc.controller;

import com.sun.org.apache.bcel.internal.generic.MONITORENTER;
import com.sun.org.apache.xpath.internal.operations.Mod;
import net.zjitc.pojo.Student;
import net.zjitc.service.StudentService;
import net.zjitc.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class StudentController {
    @Autowired
    StudentService studentService;
    @RequestMapping(value = "/register")
    public String register(Model model,Student student){
        studentService.insert(student);
        return "/findAll.do";
    }
    @RequestMapping(value = "/modifyUI")
    public String modify(Model model,Student student){
        Student student1 = studentService.selectByID(student);
//        Date date = student1.getDate();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        String format = simpleDateFormat.format(date);
//        Date parse=null;
//        try {
//             parse = simpleDateFormat.parse(format);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        student1.setDate(parse);
        model.addAttribute("student",student1);
        return "modify.jsp";
    }
    @RequestMapping(value = "/modify")
    public String modify(Student student){
        studentService.update(student);
        return "/findAll.do";
    }
    @RequestMapping(value = "/del")
    public String del(Model model,Student student){
        studentService.del(student);
        return "/findAll.do";
    }
    @RequestMapping(value = "/findAll")
    public String findAll(Model model){
//
//      StudentService studentService=new StudentServiceImpl();
        List<Student> all = studentService.findAll();
        for (Student s:all){

            System.out.println(s);
        }
        model.addAttribute("list",all);

        return "user.jsp";
    }
}
